# Customize Dataset
This documentation presents how to add a new dataset and apply it to the ***LibSignal***.
Currently, ***LibSignal*** supports the format of `.json` in CityFlow and `.net.xml` in SUMO for **Road Network File**, while `.json` in CityFlow and `.rou.xml` in SUMO for **Traffic Flow File**. It is also required `.sumocfg` file in SUMO.
For all datasets, `.cfg` file is required to configure basic information.
## Customize Road Network File
To begin with, we should create **Road Network File**. It stores the basic structure of a traffic network consisting of road, lane, and traffic light information. Here, we introduce how to create a **Road Network File** named "NewRoadNet" in CityFlow and SUMO.
### CityFlow
CityFlow's **Road Network File** mainly consists of intersections and roads.
For example, you can define `NewRoadNet.json` like this(Details can be found in [CityFlow.RoadNetworkFile](https://cityflow.readthedocs.io/en/latest/roadnet.html)):
```
{
"intersections": [
{
// id of the intersection
"id": "intersection_1_0",
// coordinate of center of intersection
"point": {
"x": 0,
"y": 0
},
// width of the intersection
"width": 10,
// roads connected to the intersection
"roads": [
"road_1",
"road_2"
],
// roadLinks of the intersection
"roadLinks": [
{
// 'turn_left', 'turn_right', 'go_straight'
"type": "go_straight",
// id of starting road
"startRoad": "road_1",
// id of ending road
"endRoad": "road_2",
// lanelinks of roadlink
"laneLinks": [
{
// from startRoad's startLaneIndex lane to endRoad's endLaneIndex lane
"startLaneIndex": 0,
"endLaneIndex": 1,
// points along the laneLink which describe the shape of laneLink
"points": [
{
"x": -10,
"y": 2
},
{
"x": 10,
"y": -2
}
]
}
]
}
],
// traffic light plan of the intersection
"trafficLight": {
"lightphases": [
{
// default duration of the phase
"time": 30,
// available roadLinks of current phase, index is the no. of roadlinks defined above.
"availableRoadLinks": [
0,
2
]
}
]
},
// true if it's a peripheral intersection (if it only connects to one road, this rule is not applied in SUMO)
"virtual": false,
// identify the virtual intersections of SUMO, this key word appeared in the file about converting SUMO file to CityFlow file
"gt_virtual": false
}
],
"roads": [
{
// id of road
"id": "road_1",
// id of start intersection
"startIntersection": "intersection_1",
// id of end intersection
"endIntersection": "intersection_2",
// points along the road which describe the shape of the road
"points": [
{
"x": -200,
"y": 0
},
{
"x": 0,
"y": 0
}
],
// property of each lane
"lanes": [
{
"width": 4,
"maxSpeed": 16.67
}
]
}
]
}
```
### SUMO
SUMO's **Road Network File** mainly consists of edges, junctions, connections and others.
Here, we introduce how to create a simple road network named `NewRoadNet.net.xml`. Details can be found in [SUMO.RoadNetworkFile](https://sumo.dlr.de/docs/Networks/SUMO_Road_Networks.html).
```
```
## Customize Traffic Flow File
Then, we should create **Traffic Flow File**. It defines the traffic flow and stores the vehicles' information.
Here, we introduce how to create a **Traffic Flow File** named `NewFlow` in CityFlow and SUMO.
### CityFlow
CityFlow's traffic flow defines vehicles' basic information, routes, depart time and others.
For example, you can define `NewFlow.json` like this(Details can be found in [CityFlow.TrafficFlowFile](https://cityflow.readthedocs.io/en/latest/flow.html)):
```
[
{
// vehicles' basic information
"vehicle": {
"length": 5.0,
"width": 2.0,
"maxPosAcc": 2.0,
"maxNegAcc": 4.5,
"usualPosAcc": 2.0,
"usualNegAcc": 4.5,
"minGap": 2.5,
"maxSpeed": 11.11,
"headwayTime": 2.0
},
// vehicle's routes
"route": [
"road_0_1_0",
"road_1_1_0"
],
// interval of consecutive vehicles
"interval": 5,
// start time of generating the vehicle
"startTime": 0,
// end time of generating the vehicle
"endTime": 0
}
]
```
### SUMO
SUMO's traffic flow defines different types of vehicles' basic information, routes and depart time.
For example, you can define `NewFlow.rou.xml` like this(Details can be found in [SUMO.TrafficFlowFile](https://sumo.dlr.de/docs/Definition_of_Vehicles%2C_Vehicle_Types%2C_and_Routes.html)):
```
```
## Customize Configuration File
**Configuration File** defines the parameters and file path. It is stored in `LibSignal/configs/sim/` folder. Different simulators and datasets require different files.
Here, we introduce how to create a **Configuration File** for a new dataset, named `NewNetwork`, that its **Road Network File**s are `NewRoadNet.json` and `NewRoadNet.net.xml` in CityFlow and SUMO, and **Traffic Flow File**s are `NewFlow.json` and `NewFlow.rou.xml` in CityFlow and SUMO respectively.
### CityFlow
For example, you can define `cityflow_NewNetwork.cfg` like this:
```
{
"network": "NewNetwork",
"interval": 1.0,
"seed": 0,
"dir": "data/",
"roadnetFile": "raw_data/NewNetwork/NewRoadNet.json",
"flowFile": "raw_data/NewNetwork/NewFlow.json",
"rlTrafficLight": true,
"saveReplay": false,
"roadnetLogFile": "output_data/tsc/NewNetwork_ModelName/NewNetwork/0/replay/RunningTime.json",
"replayLogFile": "output_data/tsc/NewNetwork_ModelName/NewNetwork/0/replay/RunningTime.txt"
}
```
### SUMO
Users should create `.sumocfg` file that contains parameters for a traffic simulation before creating `.cfg` file. All `.sumocfg` files are stored in the corresponding dataset folder under `LibSingal/data/raw_data/` folder, for example, `NewNetwork.sumocfg` is stored in `LibSingal/data/raw_data/NewNetwork/` folder.
First, you can define `NewNetwork.sumocfg` like this:
```
```
Then, you can define `sumo_NewNetwork.cfg` like this:
```
{
"network": "NewNetwork",
"interval": 1.0,
"seed": 0,
"dir": "data/",
"combined_file": "raw_data/NewNetwork/NewNetwork.sumocfg",
"roadnetFile": "raw_data/NewNetwork/NewRoadNet.net.xml",
"flowFile": "raw_data/NewNetwork/NewFlow.rou.xml",
"convertroadnetFile": "raw_data/NewNetwork/ConvertedRoadNet.json",
"convertflowFile": "raw_data/NewNetwork/ConvertedFlow.json",
"no_warning": true,
"name": "debug",
"yellow_length": 5,
"gui": false
}
```
Now that you have learned how to add a new **Dataset**, try the following commands to use this dataset!
```
python run.py -n newnetwork
```